package com.httpClient.demo;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.testng.annotations.Test;

import java.io.IOException;

/**
 * @author bigFish
 * @Title: get的httpClient案例
 */
public class HttpClientByGet {
    @Test
    public void test() throws IOException {
        //result用来存储结果
        String result;
        //创建一个HttpGet请求
        HttpGet get = new HttpGet("http://www.baidu.com/");
        //创建执行
        CloseableHttpClient client = HttpClients.createDefault();
//        CloseableHttpClient client = HttpClientBuilder.create().build();
//        DefaultHttpClient client = new DefaultHttpClient();
        CloseableHttpResponse response = client.execute(get);
        result = EntityUtils.toString(response.getEntity(), "utf-8");
        System.out.println(result);

    }
}
